/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb.op;

/**
 * <p> JVM instruction <code>0x14 ldc2_w</code>. </p>
 */
public final class Ldc2W
    extends syntelos.xb.Op.Constant
{
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb/op","xop:ldc2-w");
    public final static int code = CODE_LDC2_W;
    public final static java.lang.String name = "ldc2-w";
    public final static int size_operands = 2;
    public final static int count_stack_pop = 0;
    public final static int count_stack_push = 1;


    public Ldc2W(org.w3c.dom.Document doc, syntelos.iou.dom.Name type){
        super(doc,type);
    }
    public Ldc2W(){
        super(NAME,false);
    }
    public Ldc2W(boolean shared){
        super(NAME,true);
    }

    private void test(){
	syntelos.xb.CF.Constants.Const constant = this.getOperandConst();
	if (null == constant)
	    throw new syntelos.xb.Error.Bug();
	else {
	    switch (constant.getTag()){
	    case syntelos.xb.CF.Constants.LONG:
	    case syntelos.xb.CF.Constants.DOUBLE:
	    case syntelos.xb.CF.Constants.STRING:
		return;
	    default:
		throw new syntelos.xb.Error.Format(constant.toString());
	    }
	}
    }
    public syntelos.iou.dom.Node decompile(){
	this.test();
	return this;
    }
    public syntelos.iou.dom.Node compile(){
	this.test();
	return this;
    }
    public int getCode(){
        return code;
    }
    public java.lang.String getName(){
        return name;
    }
    public int sizeOperands(){
        return size_operands;
    }
    public int countStackPop(){
        return count_stack_pop;
    }
    public int countStackPush(){
        return count_stack_push;
    }
    public void readCF(syntelos.xb.Class clas, syntelos.xb.Method meth, syntelos.xb.Op.Reader in)
        throws java.io.IOException
    {
        if (this.setPC(in)){
            if (0 < size_operands){
                byte[] cf = new byte[size_operands];
                in.readFully(cf,0,size_operands);
                this.setCF(cf);
		this.setOperand(this.getCFIntU2(0));
            }
        }
        else
            throw new syntelos.xb.Error.Bug();
    }
    public void writeCF(syntelos.xb.Class clas, syntelos.xb.Method meth, syntelos.xb.Op.Writer out)
        throws java.io.IOException
    {
        if (this.setPC(out)){
            byte[] cf = this.getCF();
	    this.setCFIntU2(0,this.getOperand());
	    out.write(cf);
        }
        else
            throw new syntelos.xb.Error.Bug();
    }
}
